/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* swapPairs(ListNode* head) {
        ListNode* newHead = new ListNode(0, head);
        ListNode* temp = newHead;

        while(temp->next != nullptr && temp->next->next != nullptr){
            ListNode* node1 = temp->next->next;
            ListNode* node2 = temp->next;

            temp->next = node1;
            node2->next = node1->next;
            node1->next = node2;

            temp = temp->next->next;
        }

        return newHead->next;
    }
};